from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime
from typing import Optional


class CreateMixin(BaseModel):
    """创建操作公共字段Mixin类"""
    create_by: Optional[str] = Field(None, description="创建人ID")
    
    model_config = ConfigDict(from_attributes=True)


class InfoPublishBase(BaseModel):
    """信息发布基础模型"""
    content: str = Field(..., description="信息内容（必填）")
    info_type: str = Field(..., description="信息类型（必填）", max_length=50)
    type_id: Optional[str] = Field(None, description="类型绑定ID", max_length=36)
    shop_id: Optional[str] = Field(None, description="店铺ID", max_length=36)
    tenant_id: Optional[str] = Field(None, description="租户ID", max_length=36)


class InfoPublishCreate(InfoPublishBase, CreateMixin):
    """创建信息发布的请求模型"""
    pass


class InfoPublishUpdate(BaseModel):
    """更新信息发布的请求模型"""
    content: Optional[str] = Field(None, description="信息内容")
    info_type: Optional[str] = Field(None, description="信息类型", max_length=50)
    type_id: Optional[str] = Field(None, description="类型绑定ID", max_length=36)
    update_by: Optional[str] = Field(None, description="修改人ID")
    status: Optional[int] = Field(None, description="状态 1-有效 0-失效")
    
class InfoPublishSave(InfoPublishCreate):
    """保存信息请求模型（兼容创建和更新）"""
    id: Optional[str] = Field(None, description="信息ID（更新时必填）", max_length=36)
    update_by: Optional[str] = Field(None, description="修改人ID")
    status: Optional[int] = Field(None, description="状态 1-有效 0-失效")  # 添加status字段
    
    model_config = ConfigDict(from_attributes=True)


class InfoPublishInfo(InfoPublishBase):
    """信息发布详细信息响应模型"""
    id: str = Field(..., description="信息ID")
    create_by: Optional[str] = Field(None, description="创建人ID")
    update_by: Optional[str] = Field(None, description="修改人ID")
    create_time: datetime = Field(..., description="创建时间")
    update_time: datetime = Field(..., description="修改时间")
    status: int = Field(..., description="状态 1-有效 0-失效")
    
    model_config = ConfigDict(from_attributes=True)


class PaginationMixin(BaseModel):
    """分页公共参数Mixin类"""
    pageIndex: int = Field(1, description="页码", ge=1)
    pageSize: int = Field(10, description="每页数量", ge=1, le=100)


class InfoPublishQuery(PaginationMixin):
    """信息发布查询参数模型"""
    shop_id: Optional[str] = Field(None, description="店铺ID筛选")
    tenant_id: Optional[str] = Field(None, description="租户ID筛选")
    info_type: Optional[str] = Field(None, description="信息类型筛选")
    status: Optional[int] = Field(None, description="状态筛选 1-有效 0-失效")
    
    model_config = ConfigDict(from_attributes=True)